<#assign object = doc.object>
package ${object.package}.service;

<#macro copy_resultset_to_pojo att>
	<#if att?node_name != "object" && att?node_type == "element">
		<#assign position = position + 1>
		<#if att?node_name == "boolean">
		    	if (!rs.wasNull())
		      		retval.${att.@fieldName} = Boolean.valueOf(rs.getBoolean(${position} + offset));
		    	else
		      		retval.${att.@fieldName} = null;
		<#elseif att?node_name == "date" || att?node_name == "datetime">
	    		java.sql.Date ${att.@fieldName} = rs.getDate(${position} + offset);
	    		if (${att.@fieldName} != null)
	      			retval.${att.@fieldName} = new Date(${att.@fieldName}.getTime());
	    		else
	      			retval.${att.@fieldName} = null;
    	<#elseif att?node_name=="string" || att?node_name == "html">
   			<#if att?node_name=="html" || att.@maxlength[0]?number &gt; 65000>
	      		InputStream ${att.@fieldName}Stream = rs.getBinaryStream(${position} + offset);
		      	if (${att.@fieldName}Stream != null)
		      		retval.${att.@fieldName} = org.apache.commons.io.IOUtils.toString(${att.@fieldName}Stream);			
   			<#else>
	 			retval.${att.@fieldName} = rs.getString(${position} + offset);
    		</#if>
		<#elseif att?node_name=="long">
		    	long ${att.@fieldName} = rs.getLong(${position} + offset);
		    	if (!rs.wasNull())
		      		retval.${att.@fieldName} = Long.valueOf(${att.@fieldName});
		    	else
		      		retval.${att.@fieldName} = null;
		<#elseif att?node_name=="double">
		    	double ${att.@fieldName} = rs.getDouble(${position} + offset);
		    	if (!rs.wasNull())
		      		retval.${att.@fieldName} = Double.valueOf(${att.@fieldName});
		    	else
		      		retval.${att.@fieldName} = null;
		<#elseif att?node_name=="integer">
		    	int ${att.@fieldName} = rs.getInt(${position} + offset);
		    	if (!rs.wasNull())
		      		retval.${att.@fieldName} = Integer.valueOf(${att.@fieldName});
		    	else
		      		retval.${att.@fieldName} = null;
		<#elseif att?node_name=="enum">
      			retval.${att.@fieldName} = <#if !att.@scope[0]?? || att.@scope[0] == "local">${object.name}.</#if>${att.@className}.valueOfNullSafe(rs.getString(${position} + offset));
		<#elseif att?node_name=="xml">
		    	retval.set${att.@fieldName?cap_first}(unmarshall${att.@fieldName?cap_first}(rs.getBinaryStream(${position} + offset)));
		<#else>
			ERROR, unsupported attribute type ${att?node_name}
		</#if>
	</#if>
</#macro>
<#macro copy_dates>
	<#assign position = position + 1>
				retval.creationDate = new Date(rs.getTimestamp(${position} + offset).getTime());
	<#assign position = position + 1>
				if (rs.getTimestamp(${position} + offset) != null) {
					retval.updateDate = new Date(rs.getTimestamp(${position} + offset).getTime());
				}
</#macro>
<#macro copy_resultset_to_json att>
	<#if att?node_name != "object" && att?node_type == "element">
	<#assign position = position + 1>
		<#if att?node_name == "date" || att?node_name == "datetime">
		    	out.print("\"${att.@fieldName}\":");
		    	java.sql.Date _${att.@fieldName} = rs.getDate(${position} + offset);
		    	if (_${att.@fieldName} != null) {
		    		out.print('\"');
		      		out.print(Constants.${att?node_name?upper_case}.format(new Date(_${att.@fieldName}.getTime())));
		      		out.print('\"');
		    	} else
		      		out.print(NULL);
		<#elseif att?node_name=="long" || att?node_name=="integer" || att?node_name=="double">
		    	out.print("\"${att.@fieldName}\":");
		    	String _${att.@fieldName} = rs.getString(${position} + offset);
		    	if (_${att.@fieldName} != null)
		      		out.print(_${att.@fieldName});
		    	else
		      		out.print(NULL);
		<#elseif att?node_name=="xml" || att?node_name=="html">
		    	out.print("\"${att.@fieldName}\":");
		    	if(rs.getObject(${position} + offset) != null){
		    		out.print('\"');
		    		org.apache.commons.io.IOUtils.copy(rs.getBinaryStream(${position} + offset), out);
		    		out.print('\"');
		    	} else
		    		out.print(NULL);
		<#elseif att?node_name=="boolean">
		    	out.print("\"${att.@fieldName}\":");
		    	if (rs.getObject(${position} + offset) != null) 
		    		out.print(Boolean.valueOf(rs.getBoolean(${position} + offset)));
		    	else 
		    		out.print(NULL);
		<#elseif att?node_name=="string">
		    	out.print("\"${att.@fieldName}\":");
		    	String _${att.@fieldName} = rs.getString(${position} + offset);
		    	if (_${att.@fieldName} != null) {
		    		out.print(JSONUtils.valueToString(_${att.@fieldName}));
		    	} else 
		    		out.print(NULL);
		<#elseif att?node_name=="enum">
		    	out.print("\"${att.@fieldName}\":");
		    	String _${att.@fieldName} = rs.getString(${position} + offset);
		    	if (_${att.@fieldName} != null) {
		    		out.print(JSONUtils.valueToString(_${att.@fieldName}));
		    	} else 
		    		out.print(NULL);
		<#else>
			ERROR, unsupported attribute type ${att?node_name}
		</#if>
				out.print(',');
	</#if>
</#macro>
<#macro copy_dates_to_json>
	<#assign position = position + 1>
				out.print("\"creationDate\":\"");
				out.print(rs.getTimestamp(${position} + offset).toString());
				out.print('\"');
				out.print(',');
	<#assign position = position + 1>
				java.sql.Timestamp updateDate = rs.getTimestamp(${position} + offset);
				out.print("\"updateDate\":");
				if (updateDate != null) {
					out.print('\"');
					out.print(updateDate.toString());
					out.print('\"');
				} else
					out.print(NULL);
</#macro>
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
import net.sf.json.JSONObject;
import net.sf.json.util.JSONUtils;
<#if object.attributes.set[0]??>
import net.sf.json.JSONArray;
</#if>
import java.io.*;
import java.sql.ResultSet;
import java.sql.Types;
<#if object.attributes.xml[0]??>
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.JAXBException;
import ${object.package}.model.xml.*;
</#if>
import java.text.ParseException;
import java.util.Date;
<#list doc["//enum[@scope='global']"] as enum>
import ${object.package}.model.enums.${enum.@class};
</#list>

<#if object.lazyScope[0]??>
import java.util.HashMap;
import java.util.Map;
</#if>

import ${object.package}.model.*;
import ${object.package}.model.fields.*;
import redora.rdo.api.*;
import redora.rdo.exceptions.*;
import redora.rdo.util.Constants;

public class ${object.name}Util {

	public ${object.name}Util() <#if object.attributes.xml[0]??>throws ConnectException </#if>{
	<#list object.attributes.xml as att>
		try {
			${att.@fieldName}_ctx = JAXBContext.newInstance(
				new Class[] {${att.@className}.class});
			${att.@fieldName}_m = ${att.@fieldName}_ctx.createMarshaller();
			${att.@fieldName}_um = ${att.@fieldName}_ctx.createUnmarshaller();
		} catch (JAXBException e) {
			throw new ConnectException("Failed to bind ${att.@className}!", e);
		}
	</#list>
	
	}
	<#list object.attributes.xml as att>
	private JAXBContext ${att.@fieldName}_ctx;
	private Marshaller ${att.@fieldName}_m;
	private Unmarshaller ${att.@fieldName}_um;
	</#list>
	public static final String NULL = "null";
	
	/**
	* Copies te resultset into a a ${object.name}. 
	* The resultset is default parsed by index for maximum performance.
	* @param rs	(Mandatory) ResultSet containing all fields listed in ${object.name}Fields
	* @param offset	(Mandatory) Almost always 0. When performing a query on multiple tables give the offset of the fields in the select.
	* @see ${object.name}Fields
	*/
 	public ${object.name} copy(ResultSet rs, int offset, FetchScope scope) throws CopyException {
  		${object.name} retval = new ${object.name}();
		retval.isNew = false;
		retval.fetchScope = scope;
		try {
			retval.id = Long.valueOf(rs.getLong(1 + offset));
			if (scope == FetchScope.List) {
	<#assign position = 1>
	<#list object.listScope?children as att>
		<@copy_resultset_to_pojo att=att />
	</#list>
	<@copy_dates />
			} else if (scope == FetchScope.Table) {
	<#assign position = 1>
	<#list object.tableScope?children as att>
		<@copy_resultset_to_pojo att=att />
	</#list>
	<@copy_dates />
			} else if (scope == FetchScope.Form) {
	<#assign position = 1>
	<#list object.formScope?children as att>
		<@copy_resultset_to_pojo att=att />
	</#list>
	<@copy_dates />
			} else {
				throw new CopyException("Unsupported scope " + scope);
			}
			retval.clean();
		} catch (Exception e) {
			throw new CopyException("Failed to copy from table to object ${object.name}",e);
		}
		return retval;
  	}
  	
<#if doc["/object/attributes/*[@lazy='true']"][0]??>
  	/**
	* Copies lazy loading field resultset into a Map. All the lazy=true fields will be fetched in one stroke,
	* however, fields that are not in ${object.name} are unfetched: lazy object's and set's.
	* 
	* @param rs	(Mandatory) ResultSet containing all fields listed in ${object.name}Fields
	* @param offset	(Mandatory) Almost always 0. When performing a query on multiple tables give the offset of the fields in the select.
	* @see ${object.name}Fields
	*/
	public Map<String,Object> copyLazy(ResultSet rs, int offset) throws CopyException {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
	<#assign position = 1>
	<#list object.lazyScope?children as att>
		<#if att?node_name == "string" || att?node_name == "html">
			<#assign position = position + 1>
			<#if att?node_name=="html" || att.@maxlength[0]?number &gt; 65000>
	      	java.io.InputStream ${att.@fieldName}Stream = rs.getBinaryStream(${position} + offset);
	      	if (${att.@fieldName}Stream != null) {
	      		String ${att.@fieldName} = org.apache.commons.io.IOUtils.toString(${att.@fieldName}Stream);
	      		map.put("${att.@fieldName}",${att.@fieldName});	
	      	}		
   			<#else>
			String ${att.@fieldName} = rs.getString(${position} + offset);
			map.put("${att.@fieldName}",${att.@fieldName});
			</#if>
	  	<#elseif att?node_name == "xml">
	  	<#assign position = position + 1>
	  		map.put("${att.@fieldName}",unmarshall${att.@className}(rs.getBinaryStream(${position} + offset)));
		</#if>
	</#list>
		} catch (Exception e) {
			throw new CopyException("Failed to copy lazy field from table to Map",e);
		}
		return map;
	}
</#if>
	/**
	* Copies te resultset into a JSON stream. 
	* The resultset is default parsed by index for maximum performance.
	* @param rs	(Mandatory) ResultSet containing all fields listed in ${object.name}Fields
	* @param offset	(Mandatory) Almost always 0. When performing a query on multiple tables give the offset of the fields in the select.
	* @param out (Mandatory) The output stream typically routed to your servlets' writer stream.
	**/
 	public void jsonStream(ResultSet rs, int offset, PrintWriter out, FetchScope scope) throws CopyException {
		try {
			out.print('{');
			out.print("\"id\":");
			out.print(rs.getLong(1 + offset));
			out.print(',');
			if (scope == FetchScope.List) {
				<#assign position = 1>
				<#list object.listScope?children as att>
					<@copy_resultset_to_json att=att />
				</#list>
				<@copy_dates_to_json />
			} else if (scope == FetchScope.Table) {
				<#assign position = 1>
				<#list object.tableScope?children as att>
					<@copy_resultset_to_json att=att />
				</#list>
				<@copy_dates_to_json />
			} else if (scope == FetchScope.Form) {
				<#assign position = 1>
				<#list object.formScope?children as att>
					<@copy_resultset_to_json att=att />
				</#list>
				<@copy_dates_to_json />
			} else if (scope == FetchScope.Lazy) {
				<#assign position = 1>
				<#list object.lazyScope?children as att>
					<@copy_resultset_to_json att=att />
				</#list>
				<@copy_dates_to_json />
			} else {
				throw new CopyException("Unsupported scope " + scope);
			}
			out.print('}');
		} catch (Exception e) {
			throw new CopyException("Failed to copy from ResultSet into JSON for ${object.name}",e);
		}
  	}
	
	/**
    * Copies from JSON to ${object.name}.
    * Be sure you have initialized ${object.name} before running the copy. When you copy an existing ${object.name},
    * retrieve the last version from the database. In this way it will be known which attributes have been changed.
    **/
	public void copy(JSONObject obj, ${object.name} pojo) throws CopyException, LazyException<#if object.attributes.set[0]??>, ConnectException</#if> {
		if ((obj.has(${object.name}Fields.id.name()) && !(obj.getLong(${object.name}Fields.id.name()) == pojo.getId()) || (pojo.getId() != null && !obj.has(${object.name}Fields.id.name()))))
			throw new CopyException("You are trying to update ${object.name} with id " + pojo.id + " with the values of another ${object.name} (" + obj.getLong(${object.name}Fields.id.name()) + ").",null);
		<#list object.attributes?children as att>
			<#if att?node_name == "long">
		if (obj.has(${object.name}Fields.${att.@fieldName}.name()) && obj.getString(${object.name}Fields.${att.@fieldName}.name()) != NULL )
			pojo.set${att.@fieldName?cap_first}(obj.getLong(${object.name}Fields.${att.@name}.name()));		
		else 
			pojo.set${att.@fieldName?cap_first}(null);
			<#elseif att?node_name == "integer">
		if (obj.has(${object.name}Fields.${att.@fieldName}.name()) && obj.getString(${object.name}Fields.${att.@fieldName}.name()) != NULL)
			pojo.set${att.@fieldName?cap_first}(obj.getInt(${object.name}Fields.${att.@fieldName}.name()));
		else
			pojo.set${att.@fieldName?cap_first}(null);
			<#elseif att?node_name == "double">
		if (obj.has(${object.name}Fields.${att.@fieldName}.name()) && obj.getString(${object.name}Fields.${att.@fieldName}.name()) != NULL )
			pojo.set${att.@fieldName?cap_first}(obj.getDouble(${object.name}Fields.${att.@fieldName}.name()));		
		else 
			pojo.set${att.@fieldName?cap_first}(null);
			<#elseif att?node_name == "string">
				<#if att.@lazy=="true">
		try {
			if (obj.has(${object.name}Fields.${att.@fieldName}.name()) && obj.getString(${object.name}Fields.${att.@fieldName}.name()) != NULL) 
				pojo.set${att.@fieldName?cap_first}(obj.getString(${object.name}Fields.${att.@fieldName}.name()));
			else 
				pojo.set${att.@fieldName?cap_first}(null);
		} catch(LazyException e) {
			throw new CopyException("Failed to retrieved the lazy ${att.@fieldName}", e);
		}
				<#else>
			if (obj.has(${object.name}Fields.${att.@fieldName}.name()) && obj.getString(${object.name}Fields.${att.@fieldName}.name()) != NULL) 
				pojo.set${att.@fieldName?cap_first}(obj.getString(${object.name}Fields.${att.@fieldName}.name()));
			else 
				pojo.set${att.@fieldName?cap_first}(null);
				</#if>
			<#elseif att?node_name == "html">
		try {
			if (obj.has(${object.name}Fields.${att.@fieldName}.name()) && obj.getString(${object.name}Fields.${att.@fieldName}.name()) != NULL) 
				pojo.set${att.@fieldName?cap_first}(obj.getString(${object.name}Fields.${att.@fieldName}.name()));
			else
				pojo.set${att.@fieldName?cap_first}(null);
		} catch(Exception e) {
			throw new CopyException("Failed to retrieved the html field ${att.@fieldName}", e);
		}	
			<#elseif att?node_name == "enum">
		if (obj.has(${object.name}Fields.${att.@fieldName}.name()) && obj.getString(${object.name}Fields.${att.@fieldName}.name()) != NULL)
			pojo.set${att.@fieldName?cap_first}(<#if !att.@scope[0]?? || att.@scope[0] == "local">${object.name}.</#if>${att.@className}.valueOfNullSafe(obj.getString(${object.name}Fields.${att.@fieldName}.name())));
		else 
			pojo.set${att.@fieldName?cap_first}(null);
			<#elseif att?node_name == "date" || att?node_name == "datetime">
		if (obj.has(${object.name}Fields.${att.@fieldName}.name()) && obj.getString(${object.name}Fields.${att.@fieldName}.name()) != NULL) {
			try {
				pojo.set${att.@fieldName?cap_first}(Constants.${att?node_name?upper_case}.parse(obj.getString(${object.name}Fields.${att.@fieldName}.name())));
			} catch(ParseException e) {
				throw new CopyException("Failed to copy this date: " + obj.getString(${object.name}Fields.${att.@fieldName}.name()), e);
			}
		} else 
			pojo.set${att.@fieldName?cap_first}(null);
			<#elseif att?node_name == "xml">
		if (obj.has(${object.name}Fields.${att.@fieldName}.name()) && obj.getString(${object.name}Fields.${att.@fieldName}.name()) != NULL) {
			pojo.set${att.@fieldName?cap_first}((${att.@className}) unmarshall${att.@className}(new ByteArrayInputStream(obj.getString(${object.name}Fields.${att.@fieldName}.name()).getBytes())));
		} else 
			pojo.set${att.@fieldName?cap_first}(null);
			<#elseif att?node_name == "set">
		if (obj.has("${att.@fieldName}") && obj.getString("${att.@fieldName}") != NULL) {
			JSONArray array = JSONArray.fromObject(obj.get("${att.@fieldName}"));
			for (int i = 0; i < array.size(); i++) {
				${att.@class}Util _util = new ${att.@class}Util();
				${att.@class} ${att.@fieldName} = new ${att.@class}();
				JSONObject ${att.@fieldName}Obj = array.getJSONObject(i);
				_util.copy(${att.@fieldName}Obj, ${att.@fieldName});
				try {
					pojo.get${att.@fieldName?cap_first}().add(${att.@fieldName});
				} catch(PersistenceException e) {
					throw new CopyException("Copy failed with pojo.get${att.@fieldName?cap_first}()", e);
				}
			}
		}
			<#elseif att?node_name == "boolean">
		if (obj.has(${object.name}Fields.${att.@fieldName}.name()) && obj.getString(${object.name}Fields.${att.@fieldName}.name()) != NULL)
			pojo.set${att.@fieldName?cap_first}(obj.getBoolean(${object.name}Fields.${att.@fieldName}.name()));
		else
			pojo.set${att.@fieldName?cap_first}(null);
			</#if>
		</#list>
		if (obj.has(${object.name}Fields.creationDate.name()) && obj.getString(${object.name}Fields.creationDate.name()) != NULL) {
			try {
				pojo.creationDate = new Date((Constants.DATETIME.parse(obj.getString(${object.name}Fields.creationDate.name())).getTime()/1000)*1000);
			} catch(ParseException e) {
				throw new CopyException("Failed to copy this date: " + obj.getString(${object.name}Fields.creationDate.name()), e);
			}
		}
		if (obj.has(${object.name}Fields.updateDate.name()) && obj.getString(${object.name}Fields.updateDate.name()) != NULL) {
			try {
				pojo.updateDate = new Date((Constants.DATETIME.parse(obj.getString(${object.name}Fields.updateDate.name())).getTime()/1000)*1000);
			} catch(ParseException e) {
				throw new CopyException("Failed to copy this date: " + obj.getString(${object.name}Fields.updateDate.name()), e);
			}
		}
	}
	
	/**
	* Copies from ${object.name} to PrinterWriter.
	**/
	public static void copy(${object.name} pojo, PrintWriter out) throws CopyException, LazyException {
		try {
			out.print('{');
			out.print("response:");
			out.print('{');
			out.print("status:0,data:");
			out.print('{');
			out.print("\"id\":");
			out.print(pojo.getId());
			out.print(',');
	    	<#list object.formScope?children as att>
	    		<#if att?node_type == "element">
	    			<#if !(att.@lazy[0]?? && att.@lazy == "true") && att?node_name != "xml">
		    		<#if att?node_name == "date" || att?node_name == "datetime">
	    	out.print("\"${att.@fieldName}\":");
	    	Date _${att.@fieldName} = pojo.get${att.@fieldName?cap_first}();
	    	if (_${att.@fieldName} != null) {
	    		out.print('\"');
	      		out.print(Constants.${att?node_name?upper_case}.format(new Date(_${att.@fieldName}.getTime())));
	      		out.print('\"');
	    	} else
	      		out.print(NULL);
	    			<#elseif att?node_name=="long">
	    	out.print("\"${att.@fieldName}\":");
	    	Long _${att.@fieldName} = pojo.get${att.@fieldName?cap_first}();
	    	if (_${att.@fieldName} != null)
	      		out.print(_${att.@fieldName});
	    	else
	      		out.print(NULL);
	      			<#elseif att?node_name=="integer">
	      	out.print("\"${att.@fieldName}\":");
	    	Integer _${att.@fieldName} = pojo.get${att.@fieldName?cap_first}();
	    	if (_${att.@fieldName} != null)
	      		out.print(_${att.@fieldName});
	    	else
	      		out.print(NULL);
	      			<#elseif att?node_name=="double">
	      	out.print("\"${att.@fieldName}\":");
	    	Double _${att.@fieldName} = pojo.get${att.@fieldName?cap_first}();
	    	if (_${att.@fieldName} != null)
	      		out.print(_${att.@fieldName});
	    	else
	      		out.print(NULL);
	    			<#elseif att?node_name=="xml">
	    	out.print("\"${att.@fieldName}\":");
	    	out.print(NULL);
	    			<#elseif att?node_name=="boolean">
	    	out.print("\"${att.@fieldName}\":");
	    	if (pojo.get${att.@fieldName?cap_first}() != null) 
	    		out.print(Boolean.valueOf(pojo.get${att.@fieldName?cap_first}()));
	    	else 
	    		out.print(NULL);
	    			<#elseif att?node_name=="enum">
	    	out.print("\"${att.@fieldName}\":");
	    	if (pojo.get${att.@fieldName?cap_first}() != null) {
	    		out.print('\"');
	    		out.print(pojo.get${att.@fieldName?cap_first}());
	    		out.print('\"');
	    	}
	    	else 
	    		out.print(NULL);
	    			<#elseif att?node_name != "object">
	    	out.print("\"${att.@fieldName}\":");
	    	String _${att.@fieldName} = pojo.get${att.@fieldName?cap_first}();
	    	if (_${att.@fieldName} != null) {
	      		out.print(JSONUtils.valueToString(_${att.@fieldName}));
	    	} else
	      		out.print(NULL);
		      		</#if>
		    out.print(',');
		      	</#if>
		      	</#if>
		    </#list>
			out.print("\"creationDate\":\"");
			out.print(pojo.getCreationDate().toString());
			out.print('\"');
			out.print(',');
			Date updateDate = pojo.getUpdateDate();
			out.print("\"updateDate\":");
			if (updateDate != null) {
				out.print('\"');
				out.print(updateDate.toString());
				out.print('\"');
			} else
				out.print(NULL);
			out.print('}');
			out.print('}');
			out.print('}');
		} catch (Exception e) {
			throw new CopyException("Failed to copy from ResultSet into JSON for ${object.name}",e);
		}
	}
	
	public static JSONObject getJSONValue(HttpServletRequest request) {
		JSONObject json = new JSONObject();
		for (${object.name}Fields field : ${object.name}Fields.values()) {
			if (field.sqlType == Types.BIGINT || field.sqlType == Types.INTEGER
					|| field.sqlType == Types.DECIMAL) {
				if (!StringUtils.isBlank(request.getParameter(field.name()))) {
					if (field.sqlType == Types.BIGINT)
						json.put(field.name(), Long.valueOf(request
								.getParameter(field.name())));
					else if (field.sqlType == Types.INTEGER)
						json.put(field.name(), Integer.parseInt(request
								.getParameter(field.name())));
					else if (field.sqlType == Types.DECIMAL)
						json.put(field.name(), Double.valueOf(request
								.getParameter(field.name())));
				}
			} else {
				if (!StringUtils.isEmpty(request.getParameter(field.name())))
					if (field.sqlType == Types.VARCHAR)
						json.put(field.name(), request.getParameter(field
								.name()));
					else if (field.sqlType == Types.BOOLEAN)
						json.put(field.name(), Boolean.valueOf(request
								.getParameter(field.name())));
					else
						json.put(field.name(), request.getParameter(field
								.name()));
			}
		}
		return json;
	}

	
<#list object.attributes.xml as att>
	public ${att.@className} unmarshall${att.@className}(InputStream in) throws CopyException {
		if (in != null) {
			try {
				return (${att.@className}) ${att.@fieldName}_um.unmarshal(in);
			} catch (JAXBException e) {
				throw new CopyException("Failed to bind ${att.@fieldName}!", e);
			}
		}
		return null;
	}
	public InputStream marshall(${att.@className} in) throws CopyException {
		if (in != null) {
			try {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                ${att.@fieldName}_m.marshal(in, out);
                return new ByteArrayInputStream(out.toByteArray());
			} catch (JAXBException e) {
				throw new CopyException("Failed to bind ${att.@fieldName}!", e);
			}
		}
		return null;
	}
</#list>
}
